//
//  LRXChooseSexViewController.m
//  路人侠
//
//  Created by 王涛 on 16/5/19.
//  Copyright © 2016年 zhangxulong. All rights reserved.
//

#import "LRXChooseSexViewController.h"
#import "simpleNetTask.h"
@interface LRXChooseSexViewController ()
@property (nonatomic,assign) NSInteger selectSex;
@end

@implementation LRXChooseSexViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = mainColor;
    [self setChooseSexButton];
    [self setLabel];
    [self nextStepButton];
    
}
-(void)setChooseSexButton
{
    UIButton * manbutton = [UIButton buttonWithType:UIButtonTypeCustom];
    manbutton.frame = CGRectMake(139 *wScale,517 * hScale, 92 * wScale, 200 * hScale);
    [manbutton setImage:[UIImage imageNamed:@"man"] forState:UIControlStateNormal];
    [manbutton setImage:[UIImage imageNamed:@"manSelect"] forState:UIControlStateSelected];
    [manbutton addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    manbutton.tag = 234;
    manbutton.selected = YES;
    self.selectSex = 1;
    
    
    UIButton * womanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    womanBtn.frame = CGRectMake(self.view.frame.size.width - (140 + 92) * wScale, 517 * hScale, 92 * wScale, 200 * hScale);
    [womanBtn setImage:[UIImage imageNamed:@"woman"] forState:UIControlStateNormal];
    [womanBtn setImage:[UIImage imageNamed:@"womanSelect"] forState:UIControlStateSelected];
    [womanBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    womanBtn.tag = 2345;
    
    
    [self.view addSubview:womanBtn];
    [self.view addSubview:manbutton];
    
    
}
- (void)btnClick:(UIButton *)btn
{
    btn.selected = !btn.selected;
    if (btn.tag == 234) {
        self.selectSex = 1;
        UIButton * pp = [self.view viewWithTag:2345];
        pp.selected = NO;
    }
    else
    {
        self.selectSex = 0;
        UIButton * pp = [self.view viewWithTag:234];
        pp.selected = NO;
    }
}

-(void)nextStepButton
{
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.bounds = CGRectMake(0, 0, 300 * wScale, 55 * hScale);
    button.layer.cornerRadius = 25 * hScale;
    button.layer.borderColor = [UIColor whiteColor].CGColor;
    button.layer.borderWidth = 2 * hScale;
    button.layer.masksToBounds = YES;
    [button setTitle:@"下一步" forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:34 * hScale];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button.center = CGPointMake(self.view.center.x, 900 * hScale);
    [button addTarget:self action:@selector(nextClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    
}
- (void)nextClick
{
    simpleNetTaskCallBackBlock callBackBlock = ^(NSDictionary * responseObject){
        
        NSInteger statusCode = [responseObject[@"data"][@"status_code"] integerValue];
        
        if (statusCode == 1) {
            [MBProgressHUD showSuccess:@"修改成功"];
            [self dismissViewControllerAnimated:YES completion:nil];
        }
        else
        {
            [MBProgressHUD showError:@"修改失败"];
        }
        
    };
    simpleNetTask * dataTask = [[simpleNetTask alloc]initWithLoadDataBlock:callBackBlock];
    NSDictionary * parms = @{@"sexy":[NSString stringWithFormat:@"%ld",self.selectSex]};
    [dataTask sessionDataTask:parms withUrl:userInfoUpdataUrl withMethod:@"POST"];
    
}
-(void)setLabel{
    
    UILabel *label = [[UILabel alloc]init];
    label.frame = CGRectMake(51 * wScale, 252 * hScale, 0, 0);
    label.text = @"选择性别";
    label.textColor = [UIColor whiteColor];
    label.font = [UIFont systemFontOfSize:30 * hScale];
    [label sizeToFit];
    [self.view addSubview:label];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
